﻿package cn.poco.pepsi.util.xmlpared;

import java.io.InputStream;
import java.util.ArrayList;

import org.xmlpull.v1.XmlPullParser;

import android.util.Xml;
import cn.poco.pepsi.bean.FoodPhoto;

public class PhotoXmlparse {
	//private final static String TAG = "CityXmlparse";
	private static ArrayList<FoodPhoto> photos= null;
	private static  FoodPhoto photoBean = null;
	
	public static ArrayList<FoodPhoto> getXml(InputStream inSteam) throws Exception{
		XmlPullParser xmpparse = Xml.newPullParser();   //得到解释器
		xmpparse.setInput(inSteam, "UTF-8");           //设置解释流
		int code = xmpparse.getEventType();            //得到节点信息
		while(code!=XmlPullParser.END_DOCUMENT){
			switch (code) {
			case XmlPullParser.START_DOCUMENT:
				photos=new ArrayList<FoodPhoto>();
				break;
			case XmlPullParser.START_TAG:
				if("blog".equals(xmpparse.getName())){
					photoBean = new FoodPhoto();
				}
				if(photoBean!=null){
					if("res-id".equals(xmpparse.getName())){
						String key = xmpparse.nextText();
						photoBean.setResId(key);
					}
					if("image".equals(xmpparse.getName())){
						String imgurl = xmpparse.nextText();
						photoBean.setImgUrl(imgurl);
						
					}
					
				}
				break;
			case XmlPullParser.END_TAG:
				if("blog".equals(xmpparse.getName())){
					photos.add(photoBean);
					photoBean = null;
				}
				break;
			}	
			code = xmpparse.next();
		}
		inSteam.close();
		return photos;
	}
}
